﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;



namespace GenIX
{
//<OTHERS>
//======================ДОПОЛНИТЕЛЬНЫЕ ЭЛЕМЕНТЫ УПРАВЛЕНИЯ И ОТОБРАЖЕНИЯ=================================
//</OTHERS>
    public partial class NewXML : Form
    {
//<FOCUS>
//перевод фокуса на panel1 для возможности скроллинга
//</FOCUS>
        private void PanelScrollOn(object sender, MouseEventArgs e)
        {
            panel1.Focus();
        }

//<PREVIEW>
//выбор созданного элемента
//</PREVIEW>
        private void TreePreview(object sender, MouseEventArgs e)
        {
            if (treeView1.TopNode.GetNodeCount(true) == 0)
                return;

            CurNode.BackColor = Color.White;
            CurNode.ForeColor = SystemColors.HotTrack;
            EraseAllFields(0, e);
            byte j = 0;
            int k = 0;
            if (Doc.DocumentElement.ChildNodes[treeView1.SelectedNode.Index].ChildNodes.Count >0)
            for (j = 0; j < Doc.DocumentElement.ChildNodes[treeView1.SelectedNode.Index].ChildNodes.Count; j++)
            {
                k = j + 1;
                NumberOfFields = k;
                tbName[k] = new MaskedTextBox();
                tbName[k].Parent = panel1;
                switch (k)
                {
                    case 1: tbName[k].Top = 30;
                        break;
                    case 2: tbName[k].Top = 30 + tbName[k - 1].Top;
                        break;
                    case 3: tbName[k].Top = 30 + tbName[k - 1].Top;
                        break;
                    default: tbName[k].Top = 30 + tbName[k - 1].Top;
                        break;
                }
                tbName[k].Enabled = false;
                tbName[k].BackColor = SystemColors.Control;
                tbName[k].BorderStyle = BorderStyle.FixedSingle;
                tbName[k].Width = 150;
                if (k == 1)
                    tbName[k].Left = 50;
                else tbName[k].Left = tbName[k - 1].Left;
                tbName[k].Text = Doc.DocumentElement.ChildNodes[treeView1.SelectedNode.Index].ChildNodes[j].Name;

                tbValue[k] = new MaskedTextBox();
                tbValue[k].Parent = panel1;

                if (k != 1)
                    tbValue[k].Top = 30 + tbValue[k - 1].Top;
                else
                    tbValue[k].Top = 30;

                tbValue[k].Enabled = false;
                tbValue[k].Left = tbName[k].Left + 170;
                tbValue[k].Width = 400;
                tbValue[k].Text = Doc.DocumentElement.ChildNodes[treeView1.SelectedNode.Index].ChildNodes[j].InnerText;
            }
            treeView1.SelectedNode.BackColor = Color.DarkSlateBlue;
            treeView1.SelectedNode.ForeColor = Color.White;

            CurNode = treeView1.SelectedNode;
            IncFieldButton.Enabled = DecFieldButton.Enabled = false;
            NotView = false;
            checkBox1.Enabled = false;
        }

//<NUM>
// генерация нужного количества полей,используя поле со стрелками
//</NUM>
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (numericUpDown1.Value > 50)
                numericUpDown1.Value = 50;
            int i, dif, OldVal = 0;
            OldVal = Convert.ToInt32(numericUpDown1.Value);
            if (NotView == false)
                EraseAllFieldsButton.PerformClick();
            {
                if ((OldVal > 0) & (OldVal < 3))
                {
                    if ((NumberOfFields - OldVal) < 0)
                        OldVal = 3;
                    if ((NumberOfFields - OldVal) > 0)
                        OldVal = 0;
                }
                dif = NumberOfFields - OldVal;
                if (dif < 0)
                    for (i = 1; i <= Math.Abs(dif); i++)
                    {
                        if (NumberOfFields - OldVal == 0) break;
                        IncFieldButton.PerformClick();
                    }
                if (dif > 0)
                    for (i = 1; i <= dif; i++)
                    {
                        if (NumberOfFields - OldVal == 0) break;
                        DecFieldButton.PerformClick();
                    }
            }
        }

    }
}